package com.examination.to.controller;

import com.examination.to.entity.ExamRecord;
import com.examination.to.service.impl.ExamRecordServiceImpl;
import com.examination.to.service.impl.ExamServiceImpl;
import com.examination.to.util.Result;
import com.examination.to.vo.QuestionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@RequestMapping("/exam")
@Api(tags = "考试记录模块")
public class ExamRecordController {

    @Autowired
    private ExamServiceImpl examServiceImpl;

    @Autowired
    private ExamRecordServiceImpl examRecordService;

    @PostMapping("/addExamRecord")
    @ApiOperation("收集用户的答题记录")
    public Result addExamRecord(@RequestParam(required = false)Integer id,
                                @RequestParam(required = false)String examtime,
                                @RequestParam(required = false)String starttime,
                                @RequestParam(required = false)String endtime,
                                @RequestParam(required = false)String answername,
                                @RequestBody List<QuestionVo> questionVoList) {
        return examRecordService.addExamRecord(id,examtime,questionVoList,answername,starttime,endtime);
    }

    @PostMapping("/scoreDistribution")
    public List scoreDistribution(@RequestParam Integer examid){
        return examRecordService.scoreDistribution(examid);
    }

    @PostMapping("/scoreData")
    public List scoreData(@RequestParam Integer examid){
        return examRecordService.scoreData(examid);
    }

    @PostMapping("/tableData")
    public List tableData(@RequestParam Integer examid){
        return examRecordService.tableData(examid);
    }

    @PostMapping("/rankData")
    public List rankData(@RequestParam Integer examid){
        return examRecordService.rankData(examid);
    }

    @PostMapping("/resData")
    public List resData(@RequestParam Integer examid,@RequestBody List<QuestionVo> questionVoList){
        return examRecordService.resData(examid,questionVoList);
    }

    @PostMapping("/dataDetail")
    public List dataDetail(@RequestParam Integer examid){
        return examRecordService.dataDetail(examid);
    }

    @PostMapping("/showInfo")
    public Map showInfo(@RequestParam(required = false) Integer examid,
                        @RequestBody List<QuestionVo> questionVoList){
        return examRecordService.showInfo(examid,questionVoList);
    }

    @GetMapping("/userAnswer")
    public Map userAnswer(@RequestParam Integer recordid){
        return examRecordService.userAnswer(recordid);
    }

    @PostMapping("/updateScore")
    public Result updateScore(@RequestBody ExamRecord examRecord){
        return examRecordService.updateScore(examRecord);
    }
}
